package com.aluka.nirvana.framework.core.model;

import lombok.Data;
import org.apache.commons.lang.StringUtils;

/**
 * 分页实体基类
 * @author gongli
 * @since 2020/5/8
 */
@Data
public abstract class BasePageEntity {
    private Integer pageIndex = 1;
    private Integer pageSize = 10;
    private String orderBy;
    private String orderRu = "asc";

    public String getOrderBy(){
        return StringUtils.isNotBlank(orderBy) ? toLowerUnderline(orderBy) + " " + orderRu : "";
    }

    private String toLowerUnderline(String str) {
        StringBuilder sb = new StringBuilder();
        for (char c : str.toCharArray()) {
            if (Character.isUpperCase(c)) {
                sb.append("_");
                sb.append(String.valueOf(c).toLowerCase());
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }
}
